package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark77Binding;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark77 extends BaseMark {

    LayoutWatermark77Binding binding;

    public Mark77(@NonNull Context context) {
        super(context);
    }

    public Mark77(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark77(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark77Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
            int n = binding.mid.getChildCount();
            for (int i = 1; i < n; i++) {
                binding.mid.getChildAt(i).setVisibility(View.GONE);
            }
        } else {
            binding = LayoutWatermark77Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
    }

    @Override
    public void update() {
        setText(binding.binding2, "time77", binding.binding1);
        setTime(binding.binding2, new SimpleDateFormat("HH:mm"));
        setTime(binding.binding4, new SimpleDateFormat("yyyy.MM.dd"));
        setWeek(binding.binding3);

        setText(binding.binding5, "phone77", binding.binding5);

        setText(binding.binding7, "word77", binding.binding6);

        setText(binding.binding9, "desc77", binding.binding8);
        setText(binding.binding11, "weather77", binding.binding10);

        setText(binding.binding13, "didian77", binding.binding12);
        setText(binding.binding15, "haiba77", binding.binding14);
        setText(binding.binding17, "jingwei77", binding.binding16);
        setText(binding.binding19, "beizhu77", binding.binding18);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("time77", "时间", true));
        list.add(new EditItem("phone77", "手机号"));

        list.add(new EditItem("word77", "宣传语"));
        list.add(new EditItem("desc77", "业务介绍"));
        list.add(new EditItem("weather77", "天气"));

        list.add(new EditItem("didian77", "地点"));

        list.add(new EditItem("height77", "海拔"));
        list.add(new EditItem("jingwei77", "经纬度"));
        list.add(new EditItem("beizhu77", "备注"));

        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding4, new SimpleDateFormat("yyyy.MM.dd"));
            setWeek(binding.binding3);
        } else {
            super.onValueChange(item);
        }
    }
}
